﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace FlockTest
{
    public class FlockMath
    {
        // Number Generator with Bell Distribution
        private static Random rand = new Random();
        public static float Rbd()
        {
            return (float)(rand.NextDouble() 
                + rand.NextDouble() 
                + rand.NextDouble() 
                + rand.NextDouble() 
                + rand.NextDouble() 
                + rand.NextDouble() 
                + rand.NextDouble() 
                + rand.NextDouble()) / 8F;
        }

        // #D Equations from http://www.compuphase.com/axometr.htm


        // Standard Text Book Isometric
        // x' = (x - z)·cos(30°)
        // y' = y + (x + z)·sin(30°)
        public static Vector D3_ISOMetric_MEN2536(Vector Input)
        {
            Vector transformed = Vector.Zero;

            transformed.X = (Input.X - Input.Z) * 0.15425144988758405071866214661421F + Global.BOUNDING_X ;
            transformed.Y = Input.Y + (Input.X + Input.Z) * -0.98803162409286178998774890729446F ;
            
            return transformed;
        }

        // Computerised Version of isometric
        //x' = x - z
        //y' = y + ½ (x + z)
        public static Vector D3_ISOMetric_MEN2536_C(Vector Input)
        {
            Vector transformed = Vector.Zero;

            transformed.X = (Input.X - Input.Z) + Global.BOUNDING_X ;
            transformed.Y = Input.Y + (Input.X + Input.Z) * 0.5F ;

            return transformed;
        }

        // Computerised Version of isometric with offset vertices
        //x' = x - z
        //y' = y + 0.3 (x + z)
        public static Vector D3_ISOMetric_MEN2536_C_M(Vector Input)
        {
            Vector transformed = Vector.Zero;

            transformed.X = (Input.X - Input.Z * 0.9F) + Global.BOUNDING_X;
            transformed.Y = Input.Y + (Input.X + Input.Z) * 0.3F ;

            return transformed;
        }

        // Simple Front On Perspective - My own invention
        // x = x - (x  * z/z-max)
        // y = y - (y  * z/z-max)
        public static Vector D3_FROM_PERSP(Vector Input)
        {
            Vector transformed = Vector.Zero;

            transformed.X = Input.X ;//- ((Input.X /2)  * Input.Z / Global.BOUNDING_Z) + Global.BOUNDING_X;
            transformed.Y = Input.Y ;//- ((Input.Y / 2) * Input.Z / Global.BOUNDING_Z) + Global.BOUNDING_Y;

            return transformed;
        }

   }
}
